// import { defineConfig } from 'vite'
import { ConfigEnv,defineConfig,loadEnv  } from 'vite'
import { viteMockServe } from 'vite-plugin-mock'
import vue from '@vitejs/plugin-vue'
import * as path from 'path'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers'

// https://vitejs.dev/config/
// export default defineConfig({
export default defineConfig(({ mode }: ConfigEnv) => {
  const env = loadEnv(mode, process.cwd());
  return {
    resolve: {
      alias: {
        '@': path.resolve(__dirname, 'src')
      }
    },
    server: {
      host: true,
      port: 3000,
      //本地服务器代理，解决本地接口跨域问题
      proxy:{
        [env.VITE_PROXY_BASEURL]: {
          target:env.VITE_PROXY_TARGET_URL,
          changeOrigin:true,
          rewrite:(path) => path.replace(new RegExp(`^${env.VITE_PROXY_BASEURL}`),'')
        }
      }
    },
    plugins: [
      vue(),
      viteMockServe(),
      AutoImport({
        imports: ['vue'],
        dts: 'types/auto-imports.d.ts'
      }),
      Components({
        resolvers: [AntDesignVueResolver()]
      })
    ]
  }
})
